{include file="common/head"}
<head>
<title>消息</title>

<style type="text/css">
</style>    
</head>
<body style="max-width: 1000px;">
  <div id="header"></div>

    
    <div class="container-fluid" >
    <div class="row">
        <div class="col-2" style="text-align: left;line-height: 50px;font-size: 2rem;" >
            留言管理
        </div>
        <div class="col-10" style="text-align: right;">
          <form action="/index.php/msg/index" method="post">
              <f id="query_bar" >
                  <label for="type" >消息类型：</label>
                  <select name="type" class="form-control" style="width:140px;display:initial;">
                      <option value="">所有类型</option>
                      <option value="3" {if $type==1}selected{/if}>系统提醒</option>
                      <option value="1,2" {if $type==2}selected{/if}>咨询与投诉</option>
                  </select>

                  <label for="text" >关键字</label>
                  <input class="form-control" type="text"  id="text" name="text" value="{$text}" placeholder="关键字" style="display: initial;" />
                  <button type="submit" class="btn btn-warning query" style="vertical-align: middle;" >
                      <span class="bi-search" ></span>
                  </button>

              </f>
          </form>          

        </div>
      </div>

      <table class="table table-sm table-striped">
        <tr>
          <th>序号</th>
          <th>发送人</th>
          <th>类型</th>
          <th>消息内容</th>
          <th>时间</th>
          <th>是否回复</th>
          <th>上传的图片</th>
          <th></th>
        </tr>
        {foreach $list['data'] as $k=>$kv}
          <tr>
           <td>{$k+1}</td>
            <td>{$kv['customer_id_name']}</td>
            <td>{$kv['type_name']}</td>
            <td class="long_field">{$kv['text']}</td>
            <td>{$kv['create_time']}</td>
            <td>{$kv['status_name']}</td>
            <td>
              <div>
              {if $kv['imgs']!=''}
              {foreach $kv['imgs'] as $img}
                <img class="goods_image" src='{$img}' style="height:40px;" />
              {/foreach}
              {/if}
              </div>
            </td>
            <td>
            <button class="btn btn-sm btn-info btn-view" txt ="{$kv['text']}" ><span class="bi-eye"></span> </button>
            {if $kv['type']<3}
              <button class="btn btn-sm btn-primary btn-response" msg_id="{$kv['id']}"><span class="bi-pencil"></span> </button>
            {/if}
            {if $kv['type']==3}
              <button class="btn btn-sm btn-primary btn-contact" msg_id="{$kv['id']}"><span class="bi-check"></span> </button>
            {/if}
            </td>
        </tr>
          {foreach $kv['res'] as $res}
             <tr style="background: #cfe2ff;">
             <td></td>
              <td></td>
              <td >回复</td>
              <td class="long_field" >{$res['text']}</td>
              <td >{$res['create_time']}</td>
              <td>{$res['status_name']}</td>
              <td></td>
              <td></td>
              </tr>
          {/foreach}
        {/foreach}
      </table>
    {include file="common/pagination"}
    </div>


<script type="text/javascript">
$(document).ready(function(){


    $(".goods_image").on('click',function(){
        var img = $(this).attr('src');
        if(!img.trim()) return;

        layer.open({
          type: 1,
          title:'',
          closeBtn: 0, //不显示关闭按钮
         // anim: 1,
          time: 5*1000,
          shadeClose: true, //开启遮罩关闭              
          skin: 'layui-layer-rim', 
          content: "<img src='"+img+"' style='width:100%'>"
        });
    })

    $(".btn-view").on('click',function(){
      var txt = $(this).attr('txt');
      layer.open({
        title:'查看消息',
        content:txt, 
        //type: 1,
        //skin: 'layui-layer-rim', //加上边框
        area: ['600px', '400px'] //宽高
      });

    })

    $(".btn-contact").on('click',function(){
      var id = $(this).attr('msg_id');
      $.post('/msg/set_readed',{id:id},function(res){
        console.log(res);
      })

    })    

    $(".btn-response").on('click',function(){
      var msg_id =$(this).attr('msg_id');
      layer.prompt({title: '回复消息', formType: 2}, function(text, index){
        layer.close(index);
        var text = text;

        $.post('/msg/msg_post',{to:msg_id,content:text,type:1},function(res){
          console.log(res);
        })

      });

    })







})


</script>


</body>
</html>
